home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume6 / bj1 < prev    next >
Encoding:
Internet Message Format  |  1989-07-06  |  18.8 KB

  1. Path: uunet!tektronix!tekgen!tekred!games
  2. From: games@tekred.CNA.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v06i044:  bj1 - blackjack game (first version)
  5. Message-ID: <3808@tekred.CNA.TEK.COM>
  6. Date: 6 Apr 89 00:15:11 GMT
  7. Sender: billr@tekred.CNA.TEK.COM
  8. Lines: 851
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: srt@aerospace.aero.org
  12. Posting-number: Volume 6, Issue 44
  13. Archive-name: bj1
  14.  
  15.     [Once again, two implementations arrive within days of each other.
  16.      They both have their advantages, so I'm posting both of them.  This
  17.      one has a cute curses interface that draws little cards and prompts
  18.      you with the proper move when it thinks you've made a bad decision.
  19.      The second version has configuration files for the rules specific to
  20.      several Las Vegas casinos and also has a makefile for Unix and MS-DOS. -br]
  21.  
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then unpack
  24. # it by saving it into a file and typing "sh file".  To overwrite existing
  25. # files, type "sh file -c".  You can also feed this as standard input via
  26. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  27. # will see the following message at the end:
  28. #        "End of archive 1 (of 1)."
  29. # Contents:  README Makefile blackjack.c
  30. # Wrapped by billr@saab on Wed Apr  5 17:07:10 1989
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'README' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'README'\"
  34. else
  35. echo shar: Extracting \"'README'\" \(606 characters\)
  36. sed "s/^X//" >'README' <<'END_OF_FILE'
  37. XMuch as I hate to write a Blackjack program, there don't seem to be any
  38. Xreally good ones available.  Hence this program.
  39. X
  40. XThis version allows:
  41. X
  42. X(1) Hit, Stand, Double Down, Splitting
  43. X(2) Advice (Basic Strategy)
  44. X
  45. XAs distributed, this program plays a 2 deck game using Las Vegas 
  46. Xdowntown rules (hit soft 17).  These parameters can be easily 
  47. Xmodified.
  48. X
  49. XYou can hit (h), stand, (space), double down (d), or split (s).
  50. X
  51. XThere is currently no differential betting or count.
  52. X
  53. XThe program will beep and advise you of incorrect plays according
  54. Xto the basic blackjack strategy.
  55. X
  56. XScott R. Turner (srt@cs.ucla.edu).
  57. END_OF_FILE
  58. if test 606 -ne `wc -c <'README'`; then
  59.     echo shar: \"'README'\" unpacked with wrong size!
  60. fi
  61. # end of 'README'
  62. fi
  63. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'Makefile'\"
  65. else
  66. echo shar: Extracting \"'Makefile'\" \(130 characters\)
  67. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  68. X# Makefile for Blackjack
  69. X
  70. Xbj: blackjack.c
  71. X    cc -O -o bj blackjack.c -lcurses -ltermcap
  72. X
  73. Xinstall: bj
  74. X    strip bj; mv bj /usr/games/bj
  75. END_OF_FILE
  76. if test 130 -ne `wc -c <'Makefile'`; then
  77.     echo shar: \"'Makefile'\" unpacked with wrong size!
  78. fi
  79. # end of 'Makefile'
  80. fi
  81. if test -f 'blackjack.c' -a "${1}" != "-c" ; then 
  82.   echo shar: Will not clobber existing file \"'blackjack.c'\"
  83. else
  84. echo shar: Extracting \"'blackjack.c'\" \(14933 characters\)
  85. sed "s/^X//" >'blackjack.c' <<'END_OF_FILE'
  86. X/*
  87. X *  Blackjack
  88. X *  Copyright (C) 1988 Scott R. Turner (srt@cs.ucla.edu).
  89. X *
  90. X * ----------------------------------------------------------------------
  91. X *                 LICENSE AGREEMENT
  92. X *
  93. X * You may copy and distribute copies or portions of this program
  94. X * as you receive it, in any medium, provided that you conspicuously and
  95. X * appropriately publish on each copy a valid copyright notice "Copyright
  96. X * (C) 1988 Scott R. Turner" (or with whatever year is appropriate) and keep 
  97. X * intact the notices on all files that refer to this License Agreement.
  98. X * You may not charge a fee for distribution or copying of this
  99. X * program or any program which contains this program in whole or part.
  100. X * ----------------------------------------------------------------------
  101. X *  
  102. X *  Author's Notes
  103. X *  
  104. X *  Much as I hate to write a Blackjack program, there don't seem to be any
  105. X *  really good ones available.  Hence this program.
  106. X *
  107. X *  This version allows:
  108. X *
  109. X *  (1) Hit, Stand, Double Down, Splitting
  110. X *  (2) Advice (Basic Strategy)
  111. X *
  112. X *  As distributed, this program plays a 2 deck game using Las Vegas 
  113. X *  downtown rules (hit soft 17).  These parameters can be easily 
  114. X *  modified.
  115. X *
  116. X *  You can hit (h), stand, (space), double down (d), or split (s).
  117. X *
  118. X *  There is currently no differential betting or count.
  119. X *
  120. X *  The program will beep and advise you of incorrect plays according
  121. X *  to the basic blackjack strategy.
  122. X *
  123. X *  Program Notes
  124. X *
  125. X *  To change the dealer rules, see the play_dealer routine.
  126. X *
  127. X *  To change the # of decks (to a maximum of 4), change the value
  128. X *  of numcards in main to the appropriate number.  To play more than
  129. X *  4 decks you'll also have to change some declarations.
  130. X *
  131. X *  Cards are represented as integers from 1-52.  N mod 13 gives the
  132. X *  rank of the card.  N mod 4 gives the suit.
  133. X *
  134. X *  Cards are shuffled by exchange.  The number of exchanges is set 
  135. X *  in NUMEXCHANGE.  Currently 2000.
  136. X *
  137. X *  Note various timing "delay"s in the code; these can be modified to 
  138. X *  suit your own machine.  LONGSLEEP and SHORTSLEEP for Unix-y.
  139. X * 
  140. X *  Correct_play encapsulates the "basic strategy" and determines whether
  141. X *  the player's action was correct.
  142. X */
  143. X#include <ctype.h>
  144. X#include <stdio.h>
  145. X#include <curses.h>
  146. X
  147. X#define NUMEXCHANGE 2000 
  148. X#define MESSAGES 7
  149. X#define STATUS 8
  150. X#define DEALER 3
  151. X#define DEALERLINE 2
  152. X#define PLINE1 10
  153. X#define PLINE2 18
  154. X#define LONGSLEEP 20000
  155. X#define SHORTSLEEP 5000
  156. X
  157. Xint cards[209];  /* Maximum # of cards in 4 decks.  */
  158. Xint numcards;     /* Number of cards (decks * 52)    */
  159. Xint top;       /* Top card in the deck.           */
  160. Xint player[2][21];     /* 21 is the maximum # of cards in a hand. */
  161. Xint dealer[21];
  162. Xint pnum[2],
  163. X    dnum;     /* Number actually in the hand. */
  164. Xint ptot[2], dtot;     /* Totals (?) */
  165. Xint bet[2];
  166. Xint money;
  167. Xint ddown[2];
  168. Xint stand[2];
  169. Xint split;     /* Split flag. */
  170. Xint quit;
  171. Xchar suitc[]={0,'C','D','H','S'};    /*  Suits */
  172. X
  173. X/* Session Statistics */
  174. X
  175. Xint numhands, numbust, numbj, nummp;
  176. X
  177. X/*
  178. X *  init_hand initializes all the global variables
  179. X *  pertinent to the beginning of a new hand.
  180. X *
  181. X */
  182. Xvoid init_hand()
  183. X{
  184. X    pnum[0] = pnum[1] = dnum = 0;
  185. X    ptot[0] = ptot[1] = dtot = 0;
  186. X    bet[0] = bet[1] = 2;
  187. X    ddown[0] = ddown[1] = 0;
  188. X    stand[0] = stand[1] = 0;
  189. X    split = 0;
  190. X};
  191. X
  192. X/*
  193. X *  Shuffle initializes the deck and shuffles it up.
  194. X *
  195. X */
  196. X
  197. Xvoid shuffle()
  198. X{
  199. X    int i,j,tmp;
  200. X    
  201. X    for(i=1;i<=numcards;i++)
  202. X        cards[i] = i;
  203. X    top = 1;
  204. X    
  205. X    /*
  206. X     *  Exchange.
  207. X     *
  208. X     */
  209. X    for(i=0;i<=NUMEXCHANGE;i++) {
  210. X#ifdef TURBOC      
  211. X        j = random(numcards)+1;
  212. X#else
  213. X    j = (random()%numcards)+1;
  214. X#endif    
  215. X    tmp = cards[j];
  216. X    cards[j] = cards[1];
  217. X    cards[1] = tmp;
  218. X    };
  219. X    
  220. X};
  221. X            
  222. X/*
  223. X *  Rank returns the rank of a card.
  224. X *
  225. X */
  226. Xint rank(i)
  227. X    int i;
  228. X{    
  229. X    return((i % 13) + 1);
  230. X};
  231. X
  232. X/*
  233. X *  value returns the value of a hand closest
  234. X *  to 21.
  235. X *
  236. X */
  237. Xint value(h,s)
  238. X    int *h,s;
  239. X{
  240. X    int tot, aces, i, r;
  241. X    
  242. X    tot = aces = 0;
  243. X    
  244. X    for(i=0;i<s;i++) {
  245. X        r = rank(h[i]);
  246. X    if (r == 1) aces++;
  247. X    if (r > 10) r = 10;
  248. X    tot += r;
  249. X    };
  250. X    
  251. X    while (tot < 12 && aces) {
  252. X        aces--;
  253. X    tot += 10;
  254. X    };
  255. X    
  256. X    return(tot);
  257. X};
  258. X
  259. X/*
  260. X *  Bust is similar to value, except it returns 0/1 for bust.
  261. X *
  262. X */
  263. Xint bust(h,s)
  264. X    int *h,s;
  265. X{
  266. X    int tot, i, r;
  267. X    
  268. X    tot = 0;
  269. X    
  270. X    for(i=0;i<s;i++) {
  271. X        r = rank(h[i]);
  272. X    if (r > 10) r = 10;
  273. X    tot += r;
  274. X    };
  275. X
  276. X    if (tot > 21) return(1);
  277. X    else return(0);
  278. X    
  279. X};
  280. X
  281. X/*
  282. X *  My front end to getc.
  283. X *
  284. X */
  285. Xchar mgetc(allowed)
  286. X    char *allowed;
  287. X{
  288. X    char c;
  289. X
  290. X    do {
  291. X      c = getch();
  292. X      if (islower(c)) c = toupper(c);
  293. X      if (c == 'Q') {
  294. X         clear();
  295. X         move(10,0);
  296. X     printw("Session Statistics");
  297. X     move(12,0);
  298. X     printw("   Hands played: %d.",numhands-1);
  299. X     move(13,0);
  300. X     printw("   Hands misplayed: %d.", nummp);
  301. X     move(14,0);
  302. X     printw("   Hands busted: %d.",numbust);
  303. X     move(15,0);
  304. X     printw("   Blackjacks: %d.",numbj);
  305. X     move(16,0);
  306. X     printw("   Winnings: $%d.",money);
  307. X     move(20,0);
  308. X     refresh();
  309. X         nocrmode();
  310. X     /**
  311. X     quit = 1;
  312. X     break;
  313. X     **/
  314. X           exit(1);
  315. X          };
  316. X    } while (!strchr(allowed,c));
  317. X    return(c);
  318. X    
  319. X};
  320. X
  321. X/*
  322. X *  determine_results figures out what happened with 
  323. X *  the bets.
  324. X *
  325. X */
  326. Xvoid determine_results()
  327. X{
  328. X    int i;
  329. X    
  330. X    for(i=0;i<=split;i++) {
  331. X    move(MESSAGES,0);
  332. X    clrtoeol();
  333. X        /*  First, if you bust, you lose.  */
  334. X        if (bust(player[i],pnum[i])) {
  335. X        printw("Bust!  You lose $%d.",bet[i]);
  336. X        money -= bet[i];
  337. X    } else if (bust(dealer,dnum)) {
  338. X        printw("Dealer busts.  You win $%d.",bet[i]);
  339. X        money += bet[i];
  340. X    } else if (value(dealer,dnum) == value(player[i],pnum[i])) {
  341. X            printw("Push.");    
  342. X    } else if (value(dealer,dnum) > value(player[i],pnum[i])) {
  343. X        printw("Dealer has %d.  You lose $%d.",value(dealer,dnum),bet[i]);
  344. X        money -= bet[i];
  345. X    } else {
  346. X        printw("Dealer had %d.  You win $%d.",value(dealer,dnum),bet[i]);
  347. X        money += bet[i];
  348. X    };
  349. X    move(STATUS,0);
  350. X    clrtoeol();
  351. X    printw("Stake $%d",money);
  352. X    refresh();
  353. X#ifdef TURBOC    
  354. X    delay(1500);
  355. X#else
  356. X    usleep(LONGSLEEP);
  357. X#endif
  358. X    };
  359. X};
  360. X
  361. X/*
  362. X *  display_card prints the card on the screen.
  363. X *
  364. X */
  365. Xvoid display_card(hand,num,line)
  366. X    int *hand, num, line;
  367. X{
  368. X    int r,suit,start,tot;
  369. X    
  370. X    r = (hand[num-1] % 13) + 1;
  371. X    if (r<1 || r>13) {
  372. X        move(MESSAGES,0);
  373. X    printw("Weird value: %d.\n",r);
  374. X    refresh();
  375. X    mgetc(" ");
  376. X    };
  377. X    suit = (hand[num-1] - 1 / 13)%4;
  378. X    start = 5 * (num - 1);
  379. X    move(line, start);
  380. X    printw("+----+");
  381. X    move(line + 1,start);
  382. X    printw("|    |");
  383. X    move(line + 2,start);
  384. X    printw("|    |");
  385. X    move(line + 3,start);
  386. X    printw("+----+");
  387. X    
  388. X    if (line == DEALERLINE && num == 1) {
  389. X      /* Special - hide this card. */
  390. X      move(line+1,start+1);
  391. X      printw("####");
  392. X      move(line+2,start+1);
  393. X      printw("####");
  394. X      return;
  395. X    };
  396. X
  397. X    move(line + 1,start+1);
  398. X    switch(r) {
  399. X        case 1: printw("A"); break;
  400. X    case 10: printw("10"); break;
  401. X        case 11: printw("J"); break;
  402. X    case 12: printw("Q"); break;
  403. X    case 13: printw("K"); break;
  404. X    default: printw("%d",r); break;
  405. X    };
  406. X    
  407. X    printw("%c",suitc[suit+1]);
  408. X};
  409. X
  410. X/*
  411. X *  Deal deals a card to the indicated hand or player, 
  412. X *  also displaying it on the screen at the appropriate
  413. X *  spot.
  414. X */
  415. Xvoid deal(who)
  416. X    int who;
  417. X{
  418. X    if (who == DEALER) {
  419. X        dealer[dnum++] = cards[top++];
  420. X    dtot = value(dealer,dnum);
  421. X    display_card(dealer,dnum,DEALERLINE);
  422. X    } else {
  423. X        player[who][pnum[who]++] = cards[top++];
  424. X    ptot[who] = value(player[who],pnum[who]);
  425. X    if (!who) {
  426. X        display_card(player[who],pnum[who],PLINE1);
  427. X        move(PLINE1+2,(5*pnum[who]+2));
  428. X        printw("(%d)",ptot[who]);
  429. X        } else {
  430. X        display_card(player[who],pnum[who],PLINE2);
  431. X        move(PLINE2+2,(5*pnum[who]+2));
  432. X        printw("(%d)",ptot[who]);
  433. X    };
  434. X    };
  435. X    refresh();
  436. X#ifdef TURBOC    
  437. X    delay(100);
  438. X#else
  439. X    usleep(SHORTSLEEP);
  440. X#endif
  441. X};
  442. X
  443. X/* 
  444. X *  play_dealer plays the dealers hand according to the
  445. X *  standard rules.
  446. X *
  447. X *  Downtown (hit soft 17) rules.
  448. X */
  449. Xvoid play_dealer()
  450. X{   
  451. X    while (dtot < 17 || (dtot == 17 && soft(dealer,dnum))) {
  452. X        deal(DEALER);
  453. X    };
  454. X};
  455. X
  456. X/*
  457. X *  Reveal the dealer's card.
  458. X *
  459. X */
  460. Xvoid reveal()
  461. X{
  462. X    int r,suit,start,line;
  463. X    
  464. X    r = (dealer[0] % 13) + 1;
  465. X    suit = (dealer[0] - 1 / 13)%4;
  466. X    start = 0;
  467. X    line = DEALERLINE;
  468. X    /* Special - unhide this card. */
  469. X    move(line+1,start+1);
  470. X    printw("    ");
  471. X    move(line+2,start+1);
  472. X    printw("    ");
  473. X    move(line + 1,start+1);
  474. X    switch(r) {
  475. X        case 1: printw("A"); break;
  476. X    case 10: printw("10"); break;
  477. X        case 11: printw("J"); break;
  478. X    case 12: printw("Q"); break;
  479. X    case 13: printw("K"); break;
  480. X    default: printw("%d",r); break;
  481. X    };
  482. X    
  483. X    printw("%c",suitc[suit+1]);
  484. X    refresh();
  485. X};
  486. X
  487. X/*
  488. X *  True if a hand is "soft".
  489. X *
  490. X */
  491. Xint soft(h,s)
  492. X    int *h,s;
  493. X{
  494. X    int tot, aces, i, r;
  495. X    
  496. X    tot = aces = 0;
  497. X    
  498. X    for(i=0;i<s;i++) {
  499. X        r = rank(h[i]);
  500. X    if (r == 1) aces++;
  501. X    if (r > 10) r = 10;
  502. X    tot += r;
  503. X    };
  504. X    
  505. X    if (aces && tot < 12) return(1);
  506. X    return(0);
  507. X};
  508. X
  509. Xchar correct_play(h,z)
  510. X    int *h,z;
  511. X{
  512. X    int s,t,u,r;
  513. X    
  514. X    s = soft(h,z);
  515. X    t = value(h,z);
  516. X    u = rank(dealer[1]);
  517. X    if (u > 10) u = 10;
  518. X    
  519. X    if (t < 9) return('H');
  520. X    
  521. X    /*
  522. X     *  Splitting.
  523. X     *
  524. X     */
  525. X    
  526. X    if (rank(h[0]) == rank(h[1]) && z == 2) {
  527. X        r = rank(h[0]);
  528. X        if (r == 1 || r == 8 || (r == 9 && u != 7 && u != 10 && u != 1) ||
  529. X            (r == 7 && u < 8) || (r == 6 && u < 7 && u > 2) ||
  530. X            (r == 2 && u > 3 && u < 8) ||
  531. X            (r == 3 && u > 3 && u < 8)) {
  532. X                return('S');
  533. X    };
  534. X    };
  535. X    
  536. X    /*
  537. X     *  Doubling
  538. X     *
  539. X     */
  540. X
  541. X    /*  Soft  */    
  542. X    if (s && z == 2 &&
  543. X        (((t == 18 || t == 17) && u > 2 && u < 7) ||
  544. X         ((t == 16 || t == 15) && u > 3 && u < 7) ||
  545. X         ((t == 14 || t == 13) && u > 4 && u < 7))) {
  546. X                return('D');
  547. X    }
  548. X    /*  Hard */
  549. X    if (!s && z == 2 &&
  550. X        (t == 11 && u != 1) ||
  551. X        (t == 10 && u != 1 && u != 10) ||
  552. X        (t == 9 && u > 2 && u < 7)) {
  553. X                return('D');
  554. X    }
  555. X    
  556. X    /*
  557. X     * Hit or Stand.
  558. X     *
  559. X     */
  560. X    
  561. X    if (!s) {
  562. X        /*  Hard hand. */
  563. X    if (t > 16) {
  564. X        return(' ');
  565. X    } else if (t == 12 && (u == 2 || u == 3)) {
  566. X        return('H');
  567. X    } else if (u < 7 && u != 1) {
  568. X        return(' ');
  569. X    } return('H');
  570. X    } else {
  571. X        /*  Soft hand. */
  572. X        if (t < 18) {
  573. X            return('H');
  574. X    } else if (t == 18 && (u > 8 || u == 1)) {
  575. X        return('H');
  576. X    } else return(' ');
  577. X    };
  578. X};
  579. X
  580. X    
  581. X
  582. Xmain()
  583. X{
  584. X    /*
  585. X     *  Logic
  586. X     *
  587. X     *  (1) Shuffle if necessary.
  588. X     *  (2) Initialize players.
  589. X     *  (3) Deal two cards to each player.
  590. X     *      (a) blackjack check.
  591. X     *  (4) Enter play loop.
  592. X     *      For each hand:
  593. X     *      (a) ask player what to do.
  594. X     *      (b) do it, if legal.
  595. X     *      (c) check for bust.
  596. X     *  (5) Play dealer's hand.
  597. X     *  (6) Determine results.
  598. X     *  (7) Repeat
  599. X     *
  600. X     */
  601. X     
  602. X    int i;
  603. X    char c,correct;
  604. X
  605. X#ifdef TURBOC    
  606. X    randomize();
  607. X#else
  608. X    srandom((int) time(0));
  609. X#endif
  610. X    quit = 0;
  611. X    numhands = 0;
  612. X    numbust = 0;
  613. X    numbj = 0;
  614. X    nummp = 0;
  615. X
  616. X    /*
  617. X     *  Curses initialization.
  618. X     *
  619. X     */
  620. X    initscr();
  621. X    crmode();
  622. X    noecho();
  623. X    move(0,20);
  624. X    printw("*B*L*A*C*K*J*A*C*K*");
  625. X    top = 300;
  626. X    numcards = 104;  /* 2 deck game */
  627. X
  628. X    while(!quit) {
  629. X        
  630. X       /* Shuffle check. */
  631. X       if (top >= (numcards * .60)) {
  632. X            move(MESSAGES,0);
  633. X        clrtoeol();
  634. X        printw("Shuffling...          ");
  635. X        refresh();
  636. X#ifdef TURBOC        
  637. X        delay(250);
  638. X#else
  639. X        usleep(SHORTSLEEP);
  640. X#endif
  641. X        shuffle();
  642. X    };
  643. X
  644. X        /* Initialize. */
  645. X    
  646. X        init_hand();
  647. X    
  648. X    /* Clear appropriate parts of the screen. */
  649. X    for(i=0;i<=4;i++) {
  650. X        move(DEALERLINE+i,0);
  651. X        clrtoeol();
  652. X        move(PLINE1+i,0);
  653. X        clrtoeol();
  654. X        move(PLINE2+i,0);
  655. X        clrtoeol();
  656. X        move(STATUS,0);
  657. X        clrtoeol();
  658. X        move(STATUS+1,0);
  659. X        clrtoeol();
  660. X    };
  661. X    
  662. X    /* Deal two cards to each. */
  663. X
  664. X    deal(DEALER);    
  665. X    deal(DEALER);
  666. X    deal(0);
  667. X    deal(0);
  668. X    numhands++;
  669. X    
  670. X    /*  Blackjacks? */
  671. X    
  672. X    if (dtot == 21 && ptot[0] == 21) {
  673. X        reveal();
  674. X        move(MESSAGES,0);
  675. X        clrtoeol();
  676. X        printw("Double Blackjack!  Push.");
  677. X        refresh();
  678. X#ifdef TURBOC        
  679. X        delay(1000);
  680. X#else
  681. X        usleep(LONGSLEEP);
  682. X#endif
  683. X        continue;
  684. X    } else if (dtot == 21) {
  685. X        reveal();
  686. X        move(MESSAGES,0);
  687. X        clrtoeol();
  688. X        printw("Dealer Blackjack!  You lose $%d.",bet[0]);
  689. X        money -= bet[0];
  690. X        move(STATUS,0);
  691. X        clrtoeol();
  692. X        printw("Stake $%d",money);
  693. X        refresh();
  694. X#ifdef TURBOC        
  695. X        delay(1000);
  696. X#else
  697. X        usleep(LONGSLEEP);
  698. X#endif
  699. X        continue;
  700. X    } else if (ptot[0] == 21) {
  701. X        reveal();
  702. X        move(MESSAGES,0);
  703. X        clrtoeol();
  704. X        printw("Blackjack!  You win $%d.",(bet[0]*1.5));
  705. X        money += bet[0]*1.5;
  706. X        move(STATUS,0);
  707. X        clrtoeol();
  708. X        printw("Stake $%d",money);
  709. X        refresh();
  710. X#ifdef TURBOC        
  711. X        delay(1000);
  712. X#else
  713. X        usleep(LONGSLEEP);
  714. X#endif
  715. X        numbj++;
  716. X        continue;
  717. X    };
  718. X
  719. X        /*  Play loop. */
  720. X    
  721. X    while (!stand[0] || (split && !stand[1])) {
  722. X        
  723. X       again:
  724. X        
  725. X        for(i=0;i<=split;i++)
  726. X            if (!stand[i]) {
  727. X            
  728. X            /* Go to the proper spot. */
  729. X            
  730. X            if (i == 0) move(PLINE1+2,(5*pnum[0]+6));
  731. X            else move(PLINE2+2,(5*pnum[1]+6));
  732. X            refresh();
  733. X                
  734. X                /* Ask him what to do. */
  735. X            c = mgetc(" HSD");
  736. X            correct = correct_play(player[i],pnum[i]);
  737. X            
  738. X            /* Beep to annoy him. */
  739. X            if (c != correct) {
  740. X#ifdef TURBOC
  741. X               sound(75);
  742. X               delay(100);
  743. X               sound(35);
  744. X               delay(50);
  745. X               nosound();
  746. X#else
  747. X#endif
  748. X               move(STATUS+1,0);
  749. X               printw("Correct play was '%c'.",correct);
  750. X               refresh();
  751. X               nummp++;
  752. X            };
  753. X            
  754. X                /* Do it. */
  755. X            switch(c) {
  756. X            case 'Q':
  757. X            /* quit */
  758. X            break;
  759. X
  760. X                case ' ':
  761. X                /*  Stand. */
  762. X            stand[i] = 1;
  763. X            break;
  764. X            
  765. X            case 'H':
  766. X            /*  Hit. */
  767. X            deal(i);
  768. X            break;
  769. X            
  770. X            case 'S':
  771. X            /*  Split.  */
  772. X            if (!split && pnum[0] == 2 &&
  773. X                rank(player[0][0]) == rank(player[0][1])) {
  774. X                split = 1;
  775. X                player[1][0] = player[0][1];
  776. X                pnum[0] = 1;
  777. X                display_card(player[0],1,PLINE1);
  778. X                deal(0);
  779. X                display_card(player[1],1,PLINE2);
  780. X                pnum[1] = 1;
  781. X                deal(1);
  782. X                /*  Only one card after splitting aces. */
  783. X                if (rank(player[0][0]) == 1) {
  784. X                    stand[0] = 1;
  785. X                stand[1] = 1;
  786. X                };
  787. X                goto again;
  788. X            };
  789. X            break;
  790. X            
  791. X            case 'D':
  792. X            /*  Double Down.  */
  793. X            if (pnum[i] == 2) {
  794. X                bet[i] *= 2;
  795. X                deal(i);
  796. X                stand[i] = 1;
  797. X            };
  798. X            break;
  799. X            
  800. X        };
  801. X        
  802. X        /*  Bust check.  */
  803. X        
  804. X        if (bust(player[i],pnum[i])) {
  805. X            move(MESSAGES,0);
  806. X            clrtoeol();
  807. X            printw("Bust!");
  808. X            stand[i] = 1;
  809. X            refresh();
  810. X            numbust++;
  811. X        };
  812. X        };
  813. X    };
  814. X    
  815. X    /*  Play dealers hand. */
  816. X
  817. X        reveal();
  818. X    play_dealer();
  819. X
  820. X
  821. X        /*  Determine Results. */
  822. X    
  823. X    determine_results();
  824. X
  825. X    };
  826. X    
  827. X};
  828. END_OF_FILE
  829. if test 14933 -ne `wc -c <'blackjack.c'`; then
  830.     echo shar: \"'blackjack.c'\" unpacked with wrong size!
  831. fi
  832. # end of 'blackjack.c'
  833. fi
  834. echo shar: End of archive 1 \(of 1\).
  835. cp /dev/null ark1isdone
  836. MISSING=""
  837. for I in 1 ; do
  838.     if test ! -f ark${I}isdone ; then
  839.     MISSING="${MISSING} ${I}"
  840.     fi
  841. done
  842. if test "${MISSING}" = "" ; then
  843.     echo You have the archive.
  844.     rm -f ark[1-9]isdone
  845. else
  846.     echo You still need to unpack the following archives:
  847.     echo "        " ${MISSING}
  848. fi
  849. ##  End of shell archive.
  850. exit 0
  851.